﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o;
using Domain; 

namespace DAO
{
    public static class ImagenDAO
    {
        public static Imagen Traer(long id)
        {
            using (IObjectContainer db = Connect.getDataBase())
            {
                try
                {
                    Imagen i = new Imagen();
                    i.id = id;
                    IObjectSet img = db.QueryByExample(i);

                    if (!img.HasNext())
                        return null;

                    i = (Imagen)img.Next();
                    Connect.assignId(db, (object)i);
                    return i;
                }
                finally
                {
                    db.Close();
                }
            }
        }

        public static bool Guardar(Imagen img)
        {
            using (IObjectContainer db = Connect.getDataBase())
            {
                try
                {
                    if (img.db4oid.HasValue)
                    {
                        Connect.rebindId(db, (object)img);
                    }

                    db.Store(img);
                    db.Commit();
                }
                finally
                {
                    db.Close();
                }
            }
            return true;
        }

    }
}
